import O1HD, { managers, services } from "../../../../engines/gameEngine";
import LevelLianXian_1 from "../base/LevelLianXian_1";
import LevelLianXian_1Item from "../base/LevelLianXian_1Item";

const { ccclass, property } = cc._decorator;

@ccclass
export default class LevelLianXian11 extends LevelLianXian_1 {
    time: number = 100;
    @property({ type: cc.SpriteFrame, displayName: "图片名字" })
    sps: cc.SpriteFrame[] = [];

    @property({ type: cc.Node, displayName: "图片节点" })
    spNode: cc.Node = null;

    spParamsStr: string[][] = [
        ["麻烦给我的爱人来一杯Mojito", "我喜欢阅读她微醺时的眼眸", "《Mojito》"],
        ["为什么这样子", "你拉着我说你有些犹豫", "《半岛铁盒》"],
        ["我表情悠哉 跳个大概 动作轻松自在 你学不来", "霓虹的招牌 调整好状态 在华丽的城市 等待醒来", "《本草纲目》"],
        ["躺在你学校的操场看星空", "教室里的灯还亮着你没走", "《等你下课》"],
        ["谁在用琵琶弹奏", "一曲东风破", "《东风破》"],
        ["雨下整夜", "我的爱溢出就像雨水", "《七里香》"],
        ["刮风这天 我试过握着你手", "但偏偏 雨渐渐 大到我看你不见", "《晴天》"]];

    start() {
        if (services().ossSrv.getPlatform() != "tt") this.isCountDown = false;
        super.start();
    }

    binGoAni(num: number, index: number, isLeft: boolean) {

        // this.changeTxt(index - 1);
        // this.resetSp();
        // let sp = this.spNode.getChildByName("mask").getChildByName("sp").getComponent(cc.Sprite);
        // let ani = sp.node.getComponent(cc.Animation);
        // // sp.spriteFrame = null;
        // let sps = "";
        // if(isLeft){
        //     sps = index+"_"+num;
        // }else{
        //     sps = num+"_"+index;
        // }
        // let indexNum:number = this.getSpsIndex(index);
        // sp.spriteFrame = this.sps[indexNum];

        // cc.Tween.stopAllByTarget(sp.node);
        // sp.node.opacity = 0;
        // cc.tween(sp.node).to(0.1,{opacity:255}).start();
        // ani.play("spShark");
        // let tween = cc.tween(sp.node).to(0.05,{angle:2,x:20},{easing:cc.easing.backOut}).to(0.05,{angle:x:0},{easing:cc.easing.backIn}).to(0.05,{angle:-2,x:-20},{easing:cc.easing.backOut}).to(0.05,{angle:0,x:0},{easing:cc.easing.backIn}).start();
    }

    changeTxt(index: number) {
        let label: cc.Node = this.spNode.getChildByName("nameLabel");
        let label1: cc.Node = this.spNode.getChildByName("nameLabel1");
        let label2: cc.Node = this.spNode.getChildByName("nameLabel2");
        label.getComponent(cc.Label).string = this.spParamsStr[index][2];//名字

        const lyric1 = this.spParamsStr[index][0];
        const lyric2 = this.spParamsStr[index][1];//俩歌词

        label1.getComponent(cc.Label).string = lyric1
        label2.getComponent(cc.Label).string = lyric2
    }

    resetSp() {
        let label: cc.Node = this.spNode.getChildByName("nameLabel");
        let label1: cc.Node = this.spNode.getChildByName("nameLabel1");
        let label2: cc.Node = this.spNode.getChildByName("nameLabel2");
        label.getComponent(cc.Label).string = "";//名字置空

        label1.removeAllChildren();
        label2.removeAllChildren();

        // label1.getComponent(cc.Label).string = "";
        // label2.getComponent(cc.Label).string = "";
        // soundGol.getComponent(cc.Label).string = "";
        // soundGo2l.getComponent(cc.Label).string = "";
        // soundGo.width = 0;
        // soundGo2.width = 0;

        cc.Tween.stopAllByTarget(label1);
        cc.Tween.stopAllByTarget(label2);
    }

    getSpsIndex(index: string) {
        let indexNum: number = -1;
        // let path: string = this.levelName+"/sound/" + index;
        // managers().soundMgr.stopAllSound();
        // managers().soundMgr.playSound(path);
        switch (index) {
            case "1_3":
                indexNum = 0;
                break;
            case "1_2":
                indexNum = 1;
                break;
            case "2_2":
                indexNum = 2;
                break;
            case "2_1":
                indexNum = 3;
                break;
            case "3_5":
                indexNum = 4;
                break;
            case "3_4":
                indexNum = 5;
                break;
            case "4_1":
                indexNum = 6;
                break;
            case "5_7":
                indexNum = 7;
                break;
            case "5_6":
                indexNum = 8;
                break;
            case "6_6":
                indexNum = 9;
                break;
            case "7_4":
                indexNum = 10;
                break;
        }
        this.changeTxt(indexNum);
        // this.checkWin();
        return indexNum;
    }

    checkWin() {
        console.warn("??????zmhs")
        let leftNodes: cc.Node[] = this.leftNode.children;
        for (let i = 0; i < leftNodes.length; i++) {
            let n = leftNodes[i];
            if (!n.getComponent(LevelLianXian_1Item).currentWayPoint) {
                return;
            }
        }
        console.warn("??????zmhs")
        this.canTouch = false;
        this.Win(1);
        this.isStartTime = false;
        this.isPlaySound = true;
    }
}
